package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.customer.domain.OrderTouristDto;
import com.ktgj.customer.domain.OrderTouristVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.service.IOrderTouristService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 订单游客Controller
 * 
 * @author ruoyi
 * @date 2021-10-26
 */
@ControllerAdvice
@RestController
@RequestMapping("/tourist")
public class TravelOrderTouristController extends BaseController
{
    @Autowired
    private IOrderTouristService orderTouristService;

    /**
     * 查询订单游客列表
     */
    @PreAuthorize(hasPermi = "customer:tourist:list")
    @GetMapping("/list")
    public TableDataInfo list(OrderTouristDto orderTouristDto)
    {
        startPage();
        List<OrderTouristDto> list = orderTouristService.selectOrderTouristList(orderTouristDto);
        return getDataTable(list);
    }

    /**
     * 导出订单游客列表
     */
    @PreAuthorize(hasPermi = "customer:tourist:export")
    @Log(title = "订单游客", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderTouristDto orderTouristDto) throws IOException
    {
        List<OrderTouristDto> list = orderTouristService.selectOrderTouristList(orderTouristDto);
        ExcelUtil<OrderTouristDto> util = new ExcelUtil<OrderTouristDto>(OrderTouristDto.class);
        util.exportExcel(response, list, "订单游客数据");
    }

    /**
     * 获取订单游客详细信息
     */
    @PreAuthorize(hasPermi = "customer:tourist:query")
    @GetMapping(value = "/{touristId}")
    public AjaxResult getInfo(@PathVariable("touristId") Long touristId)
    {
        return AjaxResult.success(orderTouristService.selectOrderTouristById(touristId));
    }

    /**
     * 新增订单游客
     */
    @PreAuthorize(hasPermi = "customer:tourist:add")
    @Log(title = "订单游客", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderTouristDto orderTouristDto)
    {
        return toAjax(orderTouristService.insertOrderTourist(orderTouristDto));
    }

    /**
     * 修改订单游客
     */
    @PreAuthorize(hasPermi = "customer:tourist:edit")
    @Log(title = "订单游客", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderTouristDto orderTouristDto)
    {
        return toAjax(orderTouristService.updateOrderTourist(orderTouristDto));
    }

    /**
     * 删除订单游客
     */
    @PreAuthorize(hasPermi = "customer:tourist:remove")
    @Log(title = "订单游客", businessType = BusinessType.DELETE)
	@DeleteMapping("/{touristIds}")
    public AjaxResult remove(@PathVariable Long[] touristIds)
    {
        return toAjax(orderTouristService.deleteOrderTouristByIds(touristIds));
    }

    /**
     * 添加出行人
     */
    @PostMapping("/addTourist")
    public AjaxResult addTourist(@RequestBody OrderTouristVo orderTouristVo) {
        return toAjax(orderTouristService.addTourist(orderTouristVo));
    }

    /**
     * 修改出行人
     */
    @PostMapping("/updateTourist")
    public AjaxResult updateTourist(@RequestBody OrderTouristVo orderTouristVo) {
        return toAjax(orderTouristService.updateTourist(orderTouristVo));
    }
}
